//
//  InitViewController.m
//  FreightAssistant
//
//  Created by leo on 15/11/2.
//  Copyright © 2015年 leo. All rights reserved.
//

#import "InitViewController.h"

#import "KKTabBarController.h"
#import "KKNavigationController.h"

#import "UserInfoViewController.h"
#import "HistoryViewController.h"
#import "SettingViewController.h"
#import "AboutViewController.h"


@interface InitViewController () <UITableViewDataSource, UITableViewDelegate> {
    
    UITableView *_settingTableView;
    
    UIImageView *_userImageView;
    UILabel *_userNameLabel;
}

@end

@implementation InitViewController

- (void)loadView {
    [super loadView];
    
    UIView *rootView = [self view];
    
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame: rootView.bounds];
    backgroundImageView.image = [UIImage imageNamed: @"init_background"];
    [rootView addSubview: backgroundImageView];
    [rootView sendSubviewToBack: backgroundImageView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    KKTabBarController *tabBarController = [KKTabBarController viewControllerFromStoryboard];
    [self addChildViewController: tabBarController Sideslip: true];
    [self.view addSubview: tabBarController.view];
    self.view.clipsToBounds = true;
    
    {
        UIView *userInfoView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, CGRectGetWidth(self.contentView.bounds), 150)];
        [self.contentView addSubview: userInfoView];
        
        _userImageView = [[UIImageView alloc] initWithFrame: CGRectMake(40, 40, 70, 70)];
        _userImageView.backgroundColor = [UIColor orangeColor];
        [userInfoView addSubview: _userImageView];
        
        _userNameLabel = [[UILabel alloc] initWithFrame: CGRectMake(120, 50, CGRectGetWidth(userInfoView.bounds) - 140, 20)];
        _userNameLabel.textColor = [UIColor whiteColor];
        _userNameLabel.text = @"用户名称";
        [userInfoView addSubview: _userNameLabel];
    }
    
    _settingTableView = [[UITableView alloc] initWithFrame: CGRectMake(0, 150, CGRectGetWidth(self.contentView.bounds), CGRectGetHeight(self.contentView.bounds) - 200)];
    _settingTableView.backgroundColor = [UIColor clearColor];
    _settingTableView.rowHeight = 60;
    _settingTableView.dataSource = self;
    _settingTableView.delegate = self;
    _settingTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview: _settingTableView];
    
    _settingTableView.tableHeaderView = [UIView new];
    _settingTableView.tableFooterView = [UIView new];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableView methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifier = @"";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: identifier];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    NSInteger row = indexPath.row;
    
    cell.textLabel.textColor = [UIColor whiteColor];
    
    switch (row) {
        case 0:
        {
            cell.textLabel.text = @"个人信息";
        }
            break;
        case 1:
        {
            cell.textLabel.text = @"历史单据";
        }
            break;
        case 2:
        {
            cell.textLabel.text = @"基本设置";
        }
            break;
        case 3:
        {
            cell.textLabel.text = @"关于我们";
        }
            break;
            
        default:
            break;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSInteger row = indexPath.row;
    
    KKNavigationController *navigationController = nil;
    
    switch (row) {
        case 0:
        {
            UserInfoViewController *userInfoViewController = [UserInfoViewController viewControllerFromStoryboard];
            userInfoViewController.showBackButton = true;
            navigationController = [[KKNavigationController alloc] initWithRootViewController: userInfoViewController];
        }
            break;
        case 1:
        {
            HistoryViewController *historyViewController = [HistoryViewController viewControllerFromStoryboard];
            historyViewController.showBackButton = true;
            navigationController = [[KKNavigationController alloc] initWithRootViewController: historyViewController];
        }
            break;
        case 2:
        {
            SettingViewController *settingViewController = [SettingViewController viewControllerFromStoryboard];
            settingViewController.showBackButton = true;
            navigationController = [[KKNavigationController alloc] initWithRootViewController: settingViewController];
        }
            break;
        case 3:
        {
            AboutViewController *aboutViewController = [AboutViewController viewControllerFromStoryboard];
            aboutViewController.showBackButton = true;
            navigationController = [[KKNavigationController alloc] initWithRootViewController: aboutViewController];
        }
            break;
            
        default:
            break;
    }
    
    if (navigationController == nil) {
        return;
    }
    
//    navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController: navigationController animated: true completion: nil];
}


@end
